<template>
  <div class="ansible-audit-container">
    <!-- 星空背景 -->
    <div class="starry-background">
      <div class="stars"></div>
      <div class="stars2"></div>
      <div class="stars3"></div>
    </div>

    <!-- 主要内容区域 -->
    <div class="audit-content">
      <!-- 页面标题 -->
      <div class="page-header glass-effect">
        <div class="header-content">
          <div class="title-section">
            <h1 class="page-title">
              <i class="fa fa-cogs"></i>
              Jenkins服务器配置
            </h1>
            <p class="page-subtitle">管理Jenkins服务器连接配置</p>
          </div>
          <div class="stats-section">
            <div class="stat-card glass-effect">
              <div class="stat-number">{{ servers.length || 0 }}</div>
              <div class="stat-label">Jenkins服务器</div>
            </div>
            <div class="stat-card glass-effect">
              <div class="stat-number">{{ servers.filter(s => s.status === 'online').length || 0 }}</div>
              <div class="stat-label">在线服务器</div>
            </div>
            <div class="stat-card glass-effect">
              <div class="stat-number">{{ servers.reduce((sum, s) => sum + (s.job_count || 0), 0) }}</div>
              <div class="stat-label">任务总数</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 工具栏：操作按钮 + 搜索过滤 -->
      <div class="search-filters glass-effect">
        <div class="toolbar-left">
          <el-button type="primary" @click="refreshServers" class="glass-button refresh-button" :loading="loading">
            <i class="fa fa-refresh"></i>
            刷新状态
          </el-button>
          <el-button @click="showAddModal" class="glass-button add-button">
            <i class="fa fa-plus"></i>
            添加Jenkins服务器
          </el-button>
          <el-button @click="testAllConnections" class="glass-button import-button" :loading="testing">
            <i class="fa fa-plug"></i>
            测试所有连接
          </el-button>
        </div>

        <div class="toolbar-right">
          <div class="search-group">
            <input
              v-model="searchText"
              type="text"
              class="glass-input"
              placeholder="搜索Jenkins服务器名称或地址..."
            />
          </div>

          <div class="filter-group">
            <select v-model="selectedStatus" class="glass-select">
              <option value="">所有状态</option>
              <option value="online">在线</option>
              <option value="offline">离线</option>
              <option value="error">错误</option>
            </select>
          </div>
        </div>
      </div>

      <!-- Jenkins服务器列表 -->
      <div class="audit-table-section glass-effect">
        <div class="section-title">
          <i class="fa fa-cogs"></i>
          Jenkins服务器列表
        </div>

        <el-table
          :data="servers"
          style="width: 100%"
          v-loading="loading"
          row-class-name="audit-row"
          class="audit-table"
        >
          <el-table-column prop="name" label="服务器名称" min-width="150">
            <template #default="scope">
              <div class="config-name">
                <i class="fa fa-cogs"></i>
                {{ scope.row.name }}
                <el-tag v-if="scope.row.is_default" type="success" size="small" style="margin-left: 8px;">默认</el-tag>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="url" label="服务器地址" min-width="200" />

          <el-table-column prop="username" label="用户名" width="120" />

          <el-table-column prop="status" label="连接状态" width="120">
            <template #default="scope">
              <el-tag
                :type="getStatusType(scope.row.status)"
                size="small"
              >
                {{ getStatusText(scope.row.status) }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column prop="job_count" label="任务数量" width="100">
            <template #default="scope">
              <span class="time-text">{{ scope.row.job_count || 0 }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="last_check" label="最后检查" width="150">
            <template #default="scope">
              <span class="time-text">{{ formatTime(scope.row.last_check) }}</span>
            </template>
          </el-table-column>

          <el-table-column label="操作" width="430" :show-overflow-tooltip="false">
            <template #default="scope">
              <div class="action-buttons-row">
                <el-button size="small" @click="testConnection(scope.row)" class="glass-button import-button">
                  <i class="fa fa-plug"></i>
                  测试
                </el-button>
                <el-button size="small" @click="syncJobs(scope.row)" class="glass-button refresh-button">
                  <i class="fa fa-refresh"></i>
                  同步
                </el-button>
                <el-button size="small" @click="editServer(scope.row)" class="glass-button sync-button">
                  <i class="fa fa-edit"></i>
                  编辑
                </el-button>
                <el-button size="small" @click="deleteServer(scope.row)" class="glass-button delete-button">
                  <i class="fa fa-trash"></i>
                  删除
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <!-- 添加/编辑服务器模态框 -->
    <div v-if="modalVisible" class="modal-overlay" @click="closeModal">
      <div class="modal-content glass-container" @click.stop>
        <div class="modal-header">
          <h3>{{ isEdit ? '编辑' : '添加' }}Jenkins服务器</h3>
          <button class="close-btn" @click="closeModal">
            <i class="fa fa-times"></i>
          </button>
        </div>

        <form @submit.prevent="saveServer" class="server-form">
          <div class="form-group">
            <label>服务器名称</label>
            <input
              v-model="form.name"
              type="text"
              class="glass-input"
              placeholder="请输入服务器名称"
              required
            />
          </div>

          <div class="form-group">
            <label>Jenkins地址</label>
            <input
              v-model="form.url"
              type="url"
              class="glass-input"
              placeholder="http://jenkins.example.com:8080"
              required
            />
          </div>

          <div class="form-group">
            <label>用户名</label>
            <input
              v-model="form.username"
              type="text"
              class="glass-input"
              placeholder="请输入Jenkins用户名"
              required
            />
          </div>

          <div class="form-group">
            <label>API Token</label>
            <input
              v-model="form.api_token"
              type="password"
              class="glass-input"
              placeholder="请输入Jenkins API Token"
              required
            />
            <div class="form-help">
              <i class="fa fa-info-circle"></i>
              在Jenkins中：用户 → 配置 → API Token → 添加新Token
            </div>
          </div>

          <div class="form-group">
            <label class="checkbox-label">
              <input
                v-model="form.is_active"
                type="checkbox"
                class="glass-checkbox"
              />
              <span class="checkmark"></span>
              启用此服务器
            </label>
          </div>

          <div class="form-actions">
            <button type="button" class="glass-button" @click="closeModal">
              取消
            </button>
            <button type="submit" class="glass-button primary" :disabled="saving">
              <i class="fa fa-save"></i>
              {{ saving ? '保存中...' : '保存' }}
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus'
import { onMounted, ref } from 'vue'

// 响应式数据
const servers = ref([])
const modalVisible = ref(false)
const isEdit = ref(false)
const saving = ref(false)
const loading = ref(false)
const testing = ref(false)
const searchText = ref('')
const selectedStatus = ref('')

const form = ref({
  id: null,
  name: '',
  url: '',
  username: '',
  api_token: '',
  is_active: true
})

// 方法
const showAddModal = () => {
  isEdit.value = false
  form.value = {
    id: null,
    name: '',
    url: '',
    username: '',
    api_token: '',
    is_active: true
  }
  modalVisible.value = true
}

const editServer = (server: any) => {
  isEdit.value = true
  form.value = { ...server }
  modalVisible.value = true
}

const closeModal = () => {
  modalVisible.value = false
}

const saveServer = async () => {
  saving.value = true
  try {
    const { jenkinsServerApi } = await import('@/api/jenkins')

    let response
    if (isEdit.value) {
      response = await jenkinsServerApi.updateServer(form.value.id, form.value)
    } else {
      response = await jenkinsServerApi.createServer(form.value)
    }

    closeModal()
    refreshServers()
    ElMessage.success(isEdit.value ? '服务器更新成功！' : '服务器创建成功！')
  } catch (error) {
    console.error('保存失败:', error)
    ElMessage.error(`保存失败: ${error.message}`)
  } finally {
    saving.value = false
  }
}

const deleteServer = async (server: any) => {
  try {
    await ElMessageBox.confirm(
      `确定要删除服务器 "${server.name}" 吗？`,
      '确认删除',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
    )
    try {
      const { jenkinsServerApi } = await import('@/api/jenkins')
      await jenkinsServerApi.deleteServer(server.id)

      refreshServers()
      ElMessage.success('服务器删除成功！')
    } catch (error) {
      console.error('删除失败:', error)
      ElMessage.error(`删除失败: ${error.message}`)
    }
  } catch (error) {
    // 用户取消删除
  }
}

const testConnection = async (server: any) => {
  try {
    const { jenkinsServerApi } = await import('@/api/jenkins')
    const response = await jenkinsServerApi.testConnection(server.id)
    const result = response.data

    if (result.success) {
      ElMessage.success({
        message: `连接测试成功！Jenkins版本: ${result.version}，节点名称: ${result.node_name}`,
        duration: 3000
      })
      refreshServers() // 刷新状态
    } else {
      ElMessage.error(`连接测试失败: ${result.message}`)
    }
  } catch (error) {
    console.error('连接测试失败:', error)
    ElMessage.error(`连接测试失败: ${error.message}`)
  }
}

const syncJobs = async (server: any) => {
  try {
    const { jenkinsServerApi } = await import('@/api/jenkins')
    const response = await jenkinsServerApi.syncJobs(server.id)
    const result = response.data

    if (result.success) {
      ElMessage.success(`任务同步成功！同步了 ${result.synced_count} 个任务`)
      refreshServers() // 刷新统计信息
    } else {
      ElMessage.error(`任务同步失败: ${result.message}`)
    }
  } catch (error) {
    console.error('同步任务失败:', error)
    ElMessage.error(`同步任务失败: ${error.message}`)
  }
}

const testAllConnections = async () => {
  testing.value = true
  try {
    const { jenkinsServerApi } = await import('@/api/jenkins')
    const response = await jenkinsServerApi.testAllConnections()
    const result = response.data

    if (result.success) {
      const successCount = result.results.filter((r: any) => r.success).length
      const totalCount = result.results.length
      ElMessage.success(`连接测试完成！成功: ${successCount}/${totalCount}`)
      refreshServers() // 刷新状态
    } else {
      ElMessage.error('测试所有连接失败')
    }
  } catch (error) {
    console.error('测试连接失败:', error)
    ElMessage.error(`测试连接失败: ${error.message}`)
  } finally {
    testing.value = false
  }
}

const refreshServers = async () => {
  loading.value = true
  try {
    const { jenkinsServerApi } = await import('@/api/jenkins')
    const response = await jenkinsServerApi.getServers()
    servers.value = response.data.results || response.data
  } catch (error) {
    console.error('获取服务器列表失败:', error)
    ElMessage.error(`获取服务器列表失败: ${error.message}`)
  } finally {
    loading.value = false
  }
}

const getStatusType = (status: string) => {
  switch (status) {
    case 'connected': return 'success'
    case 'disconnected': return 'danger'
    case 'testing': return 'warning'
    case 'error': return 'danger'
    default: return 'info'
  }
}

const getStatusText = (status: string) => {
  switch (status) {
    case 'connected': return '已连接'
    case 'disconnected': return '已断开'
    case 'testing': return '测试中'
    case 'error': return '错误'
    default: return '未知'
  }
}

const formatTime = (time: string) => {
  if (!time) return '从未'
  return new Date(time).toLocaleString('zh-CN')
}

const formatDate = (dateString: string) => {
  if (!dateString) return '-'
  return new Date(dateString).toLocaleString('zh-CN')
}

// 生命周期
onMounted(() => {
  refreshServers()
})
</script>

<style scoped>
/* 使用与Zabbix管理页面完全相同的样式 */
.ansible-audit-container {
  min-height: 100vh;
  background: linear-gradient(
    135deg,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(20, 20, 40, 0.95) 50%,
    rgba(0, 0, 0, 0.9) 100%
  );
  overflow-x: hidden;
}

.starry-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(20, 20, 40, 0.95) 50%,
    rgba(0, 0, 0, 0.9) 100%
  );
  z-index: -1;
}

.starry-background::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="40" r="0.5" fill="rgba(255,255,255,0.1)"/><circle cx="40" cy="60" r="1" fill="rgba(255,255,255,0.1)"/></svg>') repeat;
  animation: twinkle 20s linear infinite;
  pointer-events: none;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

.glass-container {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 25px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title {
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.glass-button {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  border: none;
  color: #fff;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.glass-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(79, 172, 254, 0.3);
}

.glass-button.primary {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.glass-button.primary:hover {
  box-shadow: 0 8px 25px rgba(67, 233, 123, 0.3);
}

.glass-button.danger {
  background: linear-gradient(135deg, #fd666d 0%, #f093fb 100%);
}

.glass-button.danger:hover {
  box-shadow: 0 8px 25px rgba(253, 102, 109, 0.3);
}

.glass-button.small {
  padding: 4px 8px;
  font-size: 12px;
}

.glass-button.danger {
  background: rgba(255, 99, 99, 0.2);
  border-color: rgba(255, 99, 99, 0.3);
}

.glass-button.danger:hover {
  background: rgba(255, 99, 99, 0.3);
  border-color: rgba(255, 99, 99, 0.5);
}

.servers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 20px;
}

.server-card {
  background: rgba(164, 244, 186, 0.05);
  border: 1px solid rgba(164, 244, 186, 0.2);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.3s ease;
}

.server-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  border-color: rgba(164, 244, 186, 0.4);
}

.server-card.active {
  border-color: rgba(164, 244, 186, 0.4);
}

.server-card.inactive {
  opacity: 0.6;
  border-color: rgba(255, 255, 255, 0.2);
}

.server-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.server-name {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;
}

.server-url {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  margin: 0;
  word-break: break-all;
}

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff6b6b;
}

.status-indicator.online {
  background: #51cf66;
}

.status-text {
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
}

.server-details {
  margin-bottom: 16px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.detail-item .label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.detail-item .value {
  color: #fff;
  font-size: 14px;
}

.server-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: rgba(255, 255, 255, 0.7);
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  color: #fff;
  margin-bottom: 8px;
}

.empty-state p {
  margin-bottom: 24px;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h3 {
  color: #fff;
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.close-btn:hover {
  color: #fff;
}

.server-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  font-weight: 500;
}

.glass-input {
  background: rgba(164, 244, 186, 0.1);
  border: 1px solid rgba(164, 244, 186, 0.3);
  border-radius: 8px;
  padding: 12px;
  color: #fff;
  font-size: 14px;
  transition: all 0.3s ease;
}

.glass-input:focus {
  outline: none;
  border-color: rgba(164, 244, 186, 0.5);
  background: rgba(164, 244, 186, 0.15);
}

.glass-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.form-help {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  margin-top: 4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.9);
}

.glass-checkbox {
  width: 18px;
  height: 18px;
  accent-color: #a4f4ba;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 8px;
}

.starry-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.stars, .stars2, .stars3 {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
}

.stars {
  background-image:
    radial-gradient(2px 2px at 20px 30px, #eee, transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 90px 40px, #fff, transparent);
  background-repeat: repeat;
  background-size: 200px 100px;
  animation: zoom 20s infinite linear;
}

.stars2 {
  background-image:
    radial-gradient(1px 1px at 40px 60px, #fff, transparent),
    radial-gradient(1px 1px at 120px 10px, rgba(255,255,255,0.7), transparent);
  background-repeat: repeat;
  background-size: 300px 200px;
  animation: zoom 40s infinite linear;
}

.stars3 {
  background-image:
    radial-gradient(1px 1px at 10px 10px, rgba(255,255,255,0.5), transparent);
  background-repeat: repeat;
  background-size: 400px 300px;
  animation: zoom 60s infinite linear;
}

@keyframes zoom {
  from { transform: scale(1); }
  to { transform: scale(1.5); }
}

.audit-content {
  position: relative;
  z-index: 10;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.glass-effect {
  background: rgba(164, 244, 186, 0.1);
  border: 1px solid rgba(164, 244, 186, 0.2);
  border-radius: 12px;
  backdrop-filter: blur(20px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.page-header {
  margin-bottom: 30px;
  padding: 30px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 30px;
}

.title-section h1 {
  color: rgba(255, 255, 255, 0.95);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 8px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.title-section h1 i {
  color: #a4f4ba;
  margin-right: 12px;
}

.page-subtitle {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  margin: 0;
}

.stats-section {
  display: flex;
  gap: 20px;
}

.stat-card {
  padding: 20px;
  text-align: center;
  min-width: 120px;
}

.stat-number {
  font-size: 24px;
  font-weight: bold;
  color: #a4f4ba;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.search-filters {
  margin-bottom: 30px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 12px;
}

.toolbar-left {
  display: flex;
  gap: 12px;
  align-items: center;
}

.toolbar-right {
  display: flex;
  gap: 16px;
  align-items: center;
}

.search-group {
  min-width: 200px;
}

.filter-group {
  min-width: 150px;
}

/* 原生表单样式 - 超透明效果 */
.glass-input {
  background: rgba(164, 244, 186, 0.1) !important;
  border: 1px solid rgba(164, 244, 186, 0.3) !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  color: #fff !important;
  font-size: 14px !important;
  transition: all 0.3s ease !important;
  width: 100% !important;
}

.glass-input:focus {
  outline: none !important;
  border-color: rgba(164, 244, 186, 0.5) !important;
  background: rgba(164, 244, 186, 0.15) !important;
}

.glass-input::placeholder {
  color: rgba(255, 255, 255, 0.5) !important;
}

.glass-select {
  background: rgba(164, 244, 186, 0.1) !important;
  border: 1px solid rgba(164, 244, 186, 0.3) !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  color: #fff !important;
  font-size: 14px !important;
  transition: all 0.3s ease !important;
  width: 100% !important;
}

.glass-select:focus {
  outline: none !important;
  border-color: rgba(164, 244, 186, 0.5) !important;
  background: rgba(164, 244, 186, 0.15) !important;
}

.glass-select option {
  background: #2a5298 !important;
  color: #fff !important;
}

.audit-table-section {
  padding: 30px;
  margin-bottom: 30px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title i {
  color: #a4f4ba;
}

.config-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.config-name i {
  color: #00eaff;
}

.time-text {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

/* 表格操作按钮样式 */
.el-table .el-table__cell {
  white-space: nowrap;
}

.action-buttons-row {
  display: flex;
  flex-direction: row;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
  white-space: nowrap;
  justify-content: flex-start;
}

.action-buttons-row .el-button {
  margin: 0;
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 12px;
  min-width: auto;
}

.action-buttons-row .el-button .fa {
  margin-right: 4px;
}

/* 工具栏按钮样式 - 完全照抄Zabbix页面 */
.glass-button {
  background: rgba(164, 244, 186, 0.15) !important;
  border: 1px solid rgba(164, 244, 186, 0.3) !important;
  color: rgba(255, 255, 255, 0.9) !important;
  transition: all 0.3s ease !important;
  backdrop-filter: blur(10px) !important;
  border-radius: 8px !important;
  padding: 8px 16px !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;

  &:hover {
    background: rgba(164, 244, 186, 0.25) !important;
    border-color: rgba(164, 244, 186, 0.5) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 16px rgba(164, 244, 186, 0.2) !important;
  }

  i {
    margin-right: 6px !important;
    color: #00eaff !important;
  }

  &.refresh-button {
    background: rgba(138, 43, 226, 0.2) !important;
    border-color: rgba(138, 43, 226, 0.4) !important;
    color: #ffffff !important;

    &:hover {
      background: rgba(138, 43, 226, 0.3) !important;
      border-color: rgba(138, 43, 226, 0.6) !important;
      box-shadow: 0 4px 16px rgba(138, 43, 226, 0.3) !important;
    }

    i {
      color: #8a2be2 !important;
    }
  }

  &.sync-button {
    background: rgba(59, 130, 246, 0.2) !important;
    border-color: rgba(59, 130, 246, 0.4) !important;
    color: #ffffff !important;

    &:hover {
      background: rgba(59, 130, 246, 0.3) !important;
      border-color: rgba(59, 130, 246, 0.6) !important;
      box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3) !important;
    }

    i {
      color: #3b82f6 !important;
    }
  }

  &.add-button {
    background: rgba(34, 197, 94, 0.2) !important;
    border-color: rgba(34, 197, 94, 0.4) !important;
    color: #ffffff !important;

    &:hover {
      background: rgba(34, 197, 94, 0.3) !important;
      border-color: rgba(34, 197, 94, 0.6) !important;
      box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3) !important;
    }

    i {
      color: #22c55e !important;
    }
  }

  &.import-button {
    background: rgba(6, 182, 212, 0.2) !important;
    border-color: rgba(6, 182, 212, 0.4) !important;
    color: #ffffff !important;

    &:hover {
      background: rgba(6, 182, 212, 0.3) !important;
      border-color: rgba(6, 182, 212, 0.6) !important;
      box-shadow: 0 4px 16px rgba(6, 182, 212, 0.3) !important;
    }

    i {
      color: #06b6d4 !important;
    }
  }

  &.delete-button {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: rgba(239, 68, 68, 0.4) !important;
    color: #ffffff !important;

    &:hover {
      background: rgba(239, 68, 68, 0.3) !important;
      border-color: rgba(239, 68, 68, 0.6) !important;
      box-shadow: 0 4px 16px rgba(239, 68, 68, 0.3) !important;
    }

    i {
      color: #ef4444 !important;
    }
  }
}

/* 表格样式 */
:deep(.audit-table) {
  background: transparent !important;

  .el-table__header {
    background: rgba(164, 244, 186, 0.1) !important;
  }

  .el-table__header th {
    background: transparent !important;
    border-bottom: 1px solid rgba(164, 244, 186, 0.3) !important;
    color: rgba(255, 255, 255, 0.9) !important;
    font-weight: 600 !important;
  }

  .el-table__body tr {
    background: transparent !important;

    &:hover {
      background: rgba(164, 244, 186, 0.05) !important;
    }
  }

  .el-table__body td {
    border-bottom: 1px solid rgba(164, 244, 186, 0.1) !important;
    color: rgba(255, 255, 255, 0.8) !important;
  }
}

/* Glass Select 样式 - 与GitLab页面保持一致 */
.glass-select .el-select__wrapper {
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.glass-select .el-select__placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.glass-select .el-input__inner {
  color: #ffffff;
}

/* Element Plus 选择器样式覆盖 - 使用超透明样式 */
:deep(.el-select) {
  .el-input__wrapper {
    background: rgba(164, 244, 186, 0.1) !important;
    border: 1px solid rgba(164, 244, 186, 0.3) !important;
    border-radius: 8px !important;
    box-shadow: none !important;
    transition: all 0.3s ease !important;
  }

  .el-input__inner {
    background: transparent !important;
    color: rgba(255, 255, 255, 0.9) !important;
  }

  .el-input__suffix {
    color: rgba(255, 255, 255, 0.6) !important;
  }

  .el-select__placeholder {
    color: rgba(255, 255, 255, 0.5) !important;
  }

  &:hover .el-input__wrapper {
    border-color: rgba(164, 244, 186, 0.5) !important;
    background: rgba(164, 244, 186, 0.15) !important;
  }

  &.is-focused .el-input__wrapper {
    border-color: rgba(164, 244, 186, 0.5) !important;
    background: rgba(164, 244, 186, 0.15) !important;
  }
}

:deep(.el-input) {
  .el-input__wrapper {
    background: rgba(164, 244, 186, 0.1) !important;
    border: 1px solid rgba(164, 244, 186, 0.3) !important;
    border-radius: 8px !important;
    box-shadow: none !important;
  }

  .el-input__inner {
    background: transparent !important;
    color: #fff !important;
  }

  &:hover .el-input__wrapper {
    border-color: rgba(164, 244, 186, 0.5) !important;
  }

  &.is-focus .el-input__wrapper {
    border-color: rgba(164, 244, 186, 0.5) !important;
    background: rgba(164, 244, 186, 0.15) !important;
  }
}

:deep(.el-select-dropdown) {
  background: rgba(20, 20, 20, 0.9) !important;
  backdrop-filter: blur(10px) !important;
  border: 1px solid rgba(164, 244, 186, 0.3) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
}

:deep(.el-select-dropdown__item) {
  color: rgba(255, 255, 255, 0.9) !important;
  background: transparent !important;
  transition: all 0.3s ease !important;

  &:hover {
    background: rgba(164, 244, 186, 0.1) !important;
    color: rgba(255, 255, 255, 1) !important;
  }

  &.is-selected {
    background: rgba(164, 244, 186, 0.2) !important;
    color: rgba(255, 255, 255, 1) !important;
  }
}
</style>
